package com.baozhun.mall.common.model.bean

import java.io.Serializable

/**
 *  分页数据的基类
 */
data class ApiPagerResponse<T>(
    var data: T,
    var current_page: Int, //当前页面
    var last_page: Int, //最后一页
    var total: Int, //总数据量
    var new_goods_count: Int? = 0, //更新数量
    var brand_data: MutableList<BrandInfoBean>? = null, // 列表筛选数据 - 品牌
    var category_data: MutableList<ClassifyInfo>? = null, // 列表筛选数据 - 分类
    var activity_data: ActivityDataBean? = null,
    var activity: ActivityDataBean? = null
) : Serializable {

    companion object {
        val FILTER_TYPE_BRAND = 1
        val FILTER_TYPE_CATEGORY = 2
        val FILTER_TYPE_ALL = 3
    }

    /**
     * 数据是否为空
     */
    fun isEmpty() = (data as List<*>).isEmpty()

    /**
     * 是否为刷新
     */
    fun isRefresh() = current_page == 1

    /**
     * 是否为加载更多
     */
    fun isLoadMore() = !isRefresh()

    /**
     * 是否还有更多数据
     */
    fun hasMore() = current_page < last_page

    fun getFilterItem(filterType: Int): MutableList<FilterItem> {
        val filterItems = mutableListOf<FilterItem>()

        if (!brand_data.isNullOrEmpty() && (filterType == FILTER_TYPE_BRAND || filterType == FILTER_TYPE_ALL)) {
            val brandItem = FilterItem()
            brandItem.type = "brand"
            brandItem.query_param_name = "brand_ids"
            brandItem.title = "品牌筛选"
            val itemOptions = mutableListOf<FilterOptionItem>()
            for (brand: BrandInfoBean in brand_data!!) {
                val option = FilterOptionItem()
                option.value = brand.id
                option.name = brand.brand_name
                itemOptions.add(option)
            }
            brandItem.options = itemOptions
            filterItems.add(brandItem)
        }


        if (!category_data.isNullOrEmpty() && (filterType == FILTER_TYPE_CATEGORY || filterType == FILTER_TYPE_ALL)) {
            val categoryItem = FilterItem()
            categoryItem.type = "category"
            categoryItem.query_param_name = "level_3"
            categoryItem.title = "分类筛选"
            val itemOptions = mutableListOf<FilterOptionItem>()
            for (category: ClassifyInfo in category_data!!) {
                val option = FilterOptionItem()
                option.value = category.id
                option.name = category.name
                itemOptions.add(option)
            }
            categoryItem.options = itemOptions
            filterItems.add(categoryItem)
        }

        return filterItems
    }
}